{literal}
<script type="text/javascript">
    $(document).ready(function(){
        
    	/*var urlVisualizar = '{/literal}{$_site.url}{$acaoVisualizar}{literal}';
    	var urlGerar = '{/literal}{$_site.url}{$acaoGerar}{literal}';

    	//DECIDE PELA action DO FORMULARIO
    	$("#btn_imprimir").click(function(){
    		document.form_extrato.action = urlVisualizar;
        });
    	$("#btn_gerar").click(function(){
    		document.form_extrato.action = urlGerar;
        });
        */

        var bln_impressao_emlote = "{/literal}{$bln_impressao_emlote}{literal}";
        
        $("#form_extrato").validate({
            rules: {
        		mes_referencia: { required: true }
            },
            messages: {
            	mes_referencia: { required: "Obrigatorio" }
            },
            submitHandler: function(form) {
				//jqAjaxForm(form, "div_mensagem");
				jqAjaxForm(form, "div_auxiliar");
			}
        });

        //SE EXTRATO INDIVIDUAL SOLICITA CLIENTE
		if(bln_impressao_emlote == "false")
		{
	        $("#contrato_id").numeric();

			$("#contrato_id").rules("add", {
				 required: true,
				 messages: {
				   required: "Informe um cliente",
				 }
			});

		}else{
			$("#periodo_apuracao").rules("add", {
				 required: true,
				 messages: {
				   required: "Obrigatorio",
				 }
			});
		}

        //POPULA PERIODO APURACAO
        populaSelect("periodo_apuracao", "{/literal}{$_site.url}{literal}", "gerar-extrato/select-periodo-apuracao");
        
        //POPULA MES EXERCICIO
        populaSelect("mes_referencia", "{/literal}{$_site.url}{literal}", "gerar-extrato/select-mes-geracao-extrato");
        
    	if(bln_impressao_emlote == "false")
 		{
	    	$("#cod_cliente").autocomplete("contrato/complete-codigo", {
	    		width: 400,
	    		max: 10,
	    		scroll: false,
	    		scrollHeight: 500,
	    		mustMatch:true,
	    		delay:400,
	    		formatItem: function(data, i, n, value) {
	    			return value.split("::")[0]+" - "+value.split("::")[1];
	    		},
	    		formatResult: function(data, value) {
	    			return value.split("::")[0];
	    		}
	    	});
	
	    	$("#cod_cliente").result(function(event, data, formatted) {
	    		if (data) {
	    			$("#contrato_id").val(formatted.split("::")[0]);
	    			$("#nome_cliente").val(formatted.split("::")[1]);
	    		}
	    	});
	
	    	//AUTO COMPLETE COM O NOME DE CLIENTES
	    	$("#nome_cliente").autocomplete("contrato/complete-nome", {
	    		width: 400,
	    		max: 10,
	    		scroll: false,
	    		scrollHeight: 500,
	    		mustMatch:true,
	    		delay:400,
	    		formatItem: function(data2, i2, n2, value2) {
					return value2.split("::")[0]+"  (Contrato: "+value2.split("::")[1]+")";
	    		},
	    		formatResult: function(data2, value2) {
	    			return value2.split("::")[0];
					 
	    		}
	    	});
	
	    	$("#nome_cliente").result(function(event2, data2, formatted2) {
	    		if (data2){
	    			$("#contrato_id").val(formatted2.split("::")[1]);
	    			$("#cod_cliente").val(formatted2.split("::")[1]);
	    		}
	    	});
	
 		}//fecha verifica se impressao em lote == false

    	$('#data_emissao').datepick({showOn: 'both'});
    	$('#data_emissao').mask("99/99/9999");

        //POPULA ANO EXERCICIO
        populaSelect("ano_referencia", "{/literal}{$_site.url}{literal}", "gerar-extrato/select-ano-geracao-extrato");

    }); //fecha $(
    
</script>
{/literal}
<form id="form_extrato" name="form_extrato" method="post" action="{$_site.url}{$acao}">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="mvTituloFundo">
				  <tr>
					<td>
					{if $extrato->id > 0}Editar{else}Imprimir{/if} Nota Fiscal {if $bln_impressao_emlote == "true"}em Lote{/if}
					<input type="hidden" name="cod" value="{$extrato->id}"/>
					<input type="hidden" name="bln_impressao_emlote" value="{$bln_impressao_emlote}"/>
					<input type="hidden" name="bln_gerarextrato" id="bln_gerarextrato" value="false"/>
					</td>
				  </tr>
				</table>
    		 <table width="100%" border="0" cellspacing="0" cellpadding="0">                
                <tr>
                  <td class="contForm">
                  <table width="100%" border="0" cellspacing="3" cellpadding="0">
                   {if $bln_impressao_emlote == "false"}
                   <tr>
                   	  	<td width="20%" class="fundoTituloForm">Cliente</td>
	                    <td width="80%" colspan="3">
		                   	<table width="100%">
		                    	<tr>
		                       		<td valign="top" class="bordaFormResp" width="15%">C&oacute;digo:</td>
		                       		<td valign="top" class="bordaFormResp" width="85%">Nome:</td>
						 		</tr>
						 		<tr>
		                       		<td valign="top" class="bordaFormResp"><input name="cod_cliente" type="text" class="formulario" id="cod_cliente" value="" size="10"/>
		                       		<br><input type="hidden" name="contrato_id" id="contrato_id" value=""/>
		                       		</td>
		                       		<td valign="top" class="bordaFormResp"><input name="nome_cliente" type="text" class="formulario tamanhoForm" id="nome_cliente" value="" size="40"/></td>
								</tr>
		               		</table>
	                    </td>
	 		 		</tr>
	 		 		{else}
		 		 		<tr>
	                   		<td width="20%" class="fundoTituloForm">Per&iacute;odo apura&ccedil;&atilde;o:</td>
	                    	<td width="80%" colspan="3">
	                    		<select id="periodo_apuracao" name="periodo_apuracao"></select>
	                    	</td>
		  				</tr>
	 		 		{/if}
                    <tr>
                   		<td class="fundoTituloForm">Data de emiss&atilde;o da Nota:</td>
                    	<td colspan="3" class="bordaFormResp" >
                    		<input name="data_emissao" id="data_emissao" type="text" size="10" class="formulario" value="{$smarty.now|date_format:'%d/%m/%Y'}">
                    	</td>
	  				</tr>
                        <tr>
                          <td class="fundoTituloForm">M&ecirc;s/Ano de refer&ecirc;ncia:</td>
                          <td colspan="3">
                                  <select name='mes_referencia' id='mes_referencia'></select> &nbsp;&nbsp;<select name="ano_referencia" id="ano_referencia"></select>
                          </td>
	  		</tr>
             		</table>  	
                  </td>
                </tr>
        		<tr>
                  <td class="paddingTop15 paddingBottom15" align="center"><!-- === Botões ( Salvar e Limpar ) === -->
                     <span class="paddingRight15">
                     	<input type="submit" id="btn_imprimir" value="Imprimir" class="botao">
                     </span>
                    <span class="paddingRight15">
                    <input name="limpar" type="reset" id="Limpar" value="Limpar" class="botao" />
                    </span>
                    <input type="button" value="Cancelar" onclick="cancelar(); return false;" class="botao">
                      <!-- Final === Botões ( Salvar e Limpar ) === -->                      </td>
                </tr>
              </table>	
    </form>
